#include "mouseinputmanager.h"
#include "../../common.h"

MouseInputManager* MouseInputManager::m_instance = 0;

MouseInputManager* MouseInputManager::getInstance()
{
    return m_instance;
}

MouseInputManager::MouseInputManager()
{
    removeAllClickable();
}

MouseInputManager::~MouseInputManager()
{
    removeAllClickable();
}

void MouseInputManager::createInstance()
{
    if(m_instance)
    {
        return;
    }

    m_instance = new MouseInputManager();
}

void MouseInputManager::releaseInstance()
{
    SAFE_DELETE_OBJ(m_instance);
}

void MouseInputManager::removeAllClickable()
{
     m_vector.clear();
}

bool MouseInputManager::removeClickable(Clickable* clickObj)
{
    for(std::vector<Clickable*>::iterator it = m_vector.begin(); it != m_vector.end(); it++ )
    {
        if(*it == clickObj)
        {
            m_vector.erase(it);
            return true;
        }
    }
    return false;
}

bool MouseInputManager::addClickable(Clickable* clickObj)
{
    for(unsigned int index = 0; index < m_vector.size(); index++)
    {
        if(m_vector[index] == clickObj)
            return false;
    }
    m_vector.push_back(clickObj);
    return true;
}

void MouseInputManager::checkAllClickable(int x,int y)
{
    for(unsigned int i = 0; i < m_vector.size(); i++)
    {
        if(m_vector[i]->isClickArea(x,y))
        {
            m_vector[i]->clicked(x,y);
        }
    }
}
